package com.simple.piger.controller.applyUser;


import com.alibaba.fastjson.JSONObject;
import com.simple.piger.utils.AjaxResult;
import com.simple.piger.utils.DateUtils;
import com.simple.piger.utils.PublicUtil;
import com.simple.piger.controller.BaseController;
import com.simple.piger.dto.resp.PlatformApplyUserListRespDto;
import com.simple.piger.entity.CmsSysUser;
import com.simple.piger.service.ApplyUserService;
import com.simple.piger.service.CmsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 求职人员 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/applyUser")
public class ApplyUserController extends BaseController{
    @Autowired
    private ApplyUserService applyUserService;
    @Autowired
    private CmsUserService cmsUserService;

    /**
     * 运营平台 查看的求职人员列表
     * @param hashMap
     * @return
     */
    @GetMapping("/platformApplyUserList")
    public AjaxResult platformApplyUserList(@RequestParam HashMap hashMap) {
        JSONObject jsonObject = PublicUtil.getJSONObject(hashMap);
        Integer page = jsonObject.getInteger("page");
        Integer limit = jsonObject.getInteger("limit");
        int total = applyUserService.getPlatformApplyUserListCount();
        List<PlatformApplyUserListRespDto> list = applyUserService.platformApplyUserList(page, limit);
        return success(total, list);
    }

    /**
     * 运营平台查看的 人员信息
     * @param applyUserId
     * @return
     */
    @GetMapping("/platformApplyUserDetail/{applyUserId}")
    public AjaxResult platformApplyUserDetail(@PathVariable("applyUserId") String applyUserId) {
        PlatformApplyUserListRespDto detail = applyUserService.platformApplyDetail(applyUserId);
        CmsSysUser cmsSysUser = cmsUserService.selectById(detail.getCmsSysUserId());
        detail.setLastLogin(DateUtils.dateFormat(cmsSysUser.getLastLogin(), "yyyy-MM-dd HH:mm:ss"));
        return success(detail);
    }

}
